Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist rustc dependencies #48456

Merged
merged 17 commits into from
Mar 6, 2018
Merged

Conversation

mark-i-m
Copy link
Member

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2018
@mark-i-m
Copy link
Member Author

Hopefully, travis fails because I haven't added any files to the whitelist yet! 😛

@mark-i-m
Copy link
Member Author

Hmmm... It seems that it only runs stage0 tidy? How do I get my tidy to work...

@nikomatsakis
Copy link
Contributor

@mark-i-m travis...isn't failing?

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why travis seems happy?

saw_dir = true;
let dir = t!(dir);

// skip our exceptions
for exception in EXCEPTIONS {
if dir.path()
if EXCEPTIONS.iter().any(|exception| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}| {
WHITELIST
.iter()
.all(|&(wname, wversion)| name != wname || version != wversion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it would be nice if we could report what needs to be added to the whitelist

@mark-i-m
Copy link
Member Author

Ok, it should fail now 🤞

@mark-i-m
Copy link
Member Author

MAKE IT FAILgit statusgit status

Lol, that's what I get for using !!!! in a git commit message...

@mark-i-m
Copy link
Member Author

Hmm... it looks like paths are incorrect...

@mark-i-m
Copy link
Member Author

It looks like a spurious failure... I just want to know what path the Cargo.toml for the argument of tidy is at.

@mark-i-m
Copy link
Member Author

So currently, I'm having path failures. I'm looking for a Cargo.toml in /checkout/src/Cargo.toml and there isn't one... does anyone know the correct place to find it?

[00:05:02] * 534 error codes
[00:05:02] * highest error code: E0908
[00:05:02] * 175 features
[00:05:02] Getting metadata from "/checkout/src/Cargo.toml"
[00:05:02] thread 'main' panicked at 'Unable to run `cargo metadata`: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:945:5
[00:05:02] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:05:02] 
[00:05:02] 
[00:05:02] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "--no-vendor" "--quiet"
[00:05:02] expected success, got: exit code: 101
[00:05:02] 
[00:05:02] 
[00:05:02] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:02] Build completed unsuccessfully in 0:01:57
[00:05:02] Makefile:74: recipe for target 'tidy' failed
[00:05:02] make: *** [tidy] Error 1

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2018
@alexcrichton
Copy link
Member

@mark-i-m that looks like it's perhaps failing to spawn cargo rather than failing to find Cargo.toml? By default I believe cargo isn't in PATH so rustbuild may need to pass the path to cargo down to the tidy script.

@mark-i-m
Copy link
Member Author

Ok, it seems to be working 🎉

There are currently two variables which need to be hardcoded into tidy, though:

  • The set of crates whose dependencies we want to check (currently those corresponding to the compiler)
  • The whitelist itself

So we have a choice:

  • It is conceivable that we want to have different whitelists for rustc, libstd, tooling, books, etc... In that case, maybe those variables shouldn't be hardcoded into tidy but passed in from somewhere else.
  • The simple solution for now is to just hardcode into tidy the whitelist for rustc and always check the 'librustc*' and 'libsyntax*' crates.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I think it's fine to hardcode the crates to check and whitelist in the code itself. For the crates to check you can probably just probe the entire dependency graph for dependencies from crates.io starting from rustc and rustc_trans.

#[allow(dead_code)] manifest_path: String,
}

// Not used, but needed to not confuse serde :P
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm if these aren't used, are they needed? I think serde should ignore unused fields by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... When I tried that it was giving me deserialization errors. I will take another look.


// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
static WHITELIST: &'static [(&'static str, &'static str)] = &[
// ("advapi32-sys", "0.2.0"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably ok to only check the name of the dependency and not worry about the version for now, upgrading across major versions and such tends to not bring in too large of a change at least!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I argue that it's important for security purposes to whitelist exact versions and to vet those versions before before upgrading in any way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure yeah, but I think we'll want to consider this further down the road. If we were to lock down all the versions of everything it'd cause I think picking up deps from crates.io to be too painful (or otherwise routine updates)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is part of the downside of having a super-awesome dependency system: it becomes easy to have too many dependencies. Argue that that makes code quality, security, and build times all worse.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but I think it's also best to do this incrementally rather than all at once, can this switch to just verifying the names through a whitelist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can if you would like, but I would really like not to. I feel like adding a bit of friction to adding and updating dependencies would be healthy; in this case, you would need to update WHITELIST. We can later have an RFC to potentially add more restrictions to PRs that change WHITELIST... I see that as an incremental approach as well (we add a mechanism, then add policy through an RFC).

@mark-i-m
Copy link
Member Author

@alexcrichton Ok, so I am now only checking the dependencies of rustc and rustc_trans. (I will uncomment the whitelist when the build fails). I designed the Crate type so that we can easily turn on/off version checking, as you choose.

resolve: Resolve,

// Not used, but needed to not confuse serde :P
#[allow(dead_code)] packages: Vec<Package>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this get removed? If not, how come?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

unapproved.append(&mut bad);
}

// Remove duplicates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could be passed around as &mut BTreeSet<Crate<'a>>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@alexcrichton
Copy link
Member

Can this please remove the version checking as well? That happens anyway when Cargo.lock changes and is reviewed. The purpose of this feature is to prevent accidental inclusion of extra crates from crates.io or otherwise alert ourselves to new dependencies.

@mark-i-m
Copy link
Member Author

@alexcrichton done 👍

Let me know what you think :)

@mark-i-m
Copy link
Member Author

I will uncomment the whitelist itself when the build fails...

@mark-i-m
Copy link
Member Author

Ok, I uncommented the whitelist.

@mark-i-m mark-i-m changed the title [WIP] Whitelist rustc dependencies Whitelist rustc dependencies Feb 27, 2018
@alexcrichton
Copy link
Member

Looks good to me!

I think a few more deps may need to be added though?

@mark-i-m
Copy link
Member Author

Oh, hmm... I wonder how that happened 😖

Fixed 👍

@alexcrichton
Copy link
Member

Looks like another crate is missing? Although I don't know how core got in there...

@mark-i-m
Copy link
Member Author

Hmm... different versions of a crate may have different dependencies... I think this should be fixed now.

Once again, I will wait for build failure and then enable the whitelist.

@mark-i-m
Copy link
Member Author

mark-i-m commented Mar 5, 2018

@alexcrichton Hmm... I tried rebasing on the latest master, but I didn't get any conflicts locally. Do you know what's going on here?

@alexcrichton
Copy link
Member

Ah yeah sometimes bors is not so good at merges...

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 5, 2018

📌 Commit e5d2920 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 5, 2018
@bors
Copy link
Collaborator

bors commented Mar 6, 2018

⌛ Testing commit e5d2920 with merge 1733a61...

@bors
Copy link
Collaborator

bors commented Mar 6, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 6, 2018
@alexcrichton
Copy link
Member

All dist jobs passed, merging manually

@alexcrichton alexcrichton merged commit e5d2920 into rust-lang:master Mar 6, 2018
@mark-i-m mark-i-m deleted the whitelist branch November 14, 2018 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants